<template>
  <div class="content">
    <!-- 顶部搜索栏 -->
    <div class="top">
      <a-card :bordered="false">
        <a-space :size="30">
          <a-input-search
            v-model:value="StoreCommentDto.nickName"
            style="width: 250px"
            placeholder="请输入用户昵称"
            @search="likeSearch"
            size="large"
          >
            <template #enterButton>
              <a-button style="background-color: #409eff; color: white"
                >查询</a-button
              >
            </template>
          </a-input-search>
          <a-button type="primary" @click="resetParamr" ghost
            ><ReloadOutlined />重置</a-button
          >
        </a-space>
      </a-card>
    </div>

    <!-- 表格数据展示 -->
    <div class="table">
      <a-card :bordered="false">
        <div>
          <a-spin tip="加载中" :spinning="false">
            <a-table :data-source="data" :pagination="false" :loading="loading">
              <a-table-column
                fixed="left"
                key="avatar"
                title="头像"
                data-index="avatar"
              >
                <template #default="{ record }">
                  <a-image
                    :preview="false"
                    style="border-radius: 10%"
                    :width="50"
                    :src="record.avatar"
                  />
                </template>
              </a-table-column>
              <a-table-column
                key="nickName"
                title="用户昵称"
                data-index="nickName"
              />
              <a-table-column
                key="comment"
                title="评论"
                data-index="comment"
              >
              </a-table-column>
              <a-table-column key="status" title="评分" data-index="status">
                <template #default="{ record }">
                  <a-rate disabled v-model:value="record.score" allow-half />
                </template>
              </a-table-column>
              <!-- <a-table-column fixed="right" key="id" title="操作">
                <template #default="{ record }">
                  <div>
                    <a-popconfirm
                      title="确认删除？"
                      ok-text="确认"
                      cancel-text="取消"
                      @confirm="remove(record.id)"
                    >
                      <a-button
                        type="link"
                        ghost
                        danger
                      >
                        删除
                      </a-button>
                    </a-popconfirm>
                  </div>
                </template>
              </a-table-column> -->
            </a-table>
          </a-spin>
        </div>
        <!-- 分页 -->
        <div
          style="
            height: 40px;
            width: 100%;
            margin-top: 30px;
            display: flex;
            justify-content: center;
          "
        >
          <a-pagination
            v-model:current="pageNo"
            v-model:page-size="pageSize"
            :total="total"
            @change="handlePageChange"
            :show-total="(total) => `共 ${total} 条`"
          />
        </div>
      </a-card>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { message } from "ant-design-vue";
import { useAdminStore } from "@/stores/admin";
import { findStoreComment,deleteStoreComment } from "@/api/storecomment";

const data = ref([{}]);
const loading = ref(true);
const adminStore = useAdminStore();
onMounted(() => {
  setTimeout(() => {
    getStoreComment();
    loading.value = false;
  }, 800);
});

const total = ref(0);
const pageNo = ref(1);
const pageSize = ref(10);
const StoreCommentDto = ref({
  userId: null,
  nickName: null
})

//获取店铺评论
function getStoreComment() {
  StoreCommentDto.value.userId = adminStore.admin.key;
  findStoreComment(pageNo.value, pageSize.value, StoreCommentDto.value).then((res) => {
    if (res.code === 200 && res.data !== null) {
      total.value = res.data.total;
      data.value = res.data.data;
    }
  });
}

function likeSearch(searchValue) {
  StoreCommentDto.value.nickName = searchValue;
  getStoreComment();
}

//重置模糊查询数据
function resetParamr() {
  StoreCommentDto.value.nickName = null;
  getStoreComment();
}

//监听分页变化
function handlePageChange(param1, param2) {
  pageNo.value = param1;
  pageSize.value = param2;
  getStoreComment();
}

//管理员确认删除回调操作
function remove(id) {
  deleteStoreComment(id).then((res) => {
    if (res.code === 200) {
      message.success("删除成功！");
      getStoreComment();
    }
  });
}
</script>

<style scoped>
.options {
  margin-top: 10px;
}

.table {
  margin-top: 10px;
}

.avatar-uploader > .ant-upload {
  width: 50px;
  height: 50px;
}
.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
.paginAtion {
  padding-top: 20px;
  padding-left: 310px;
  margin-bottom: 20px;
}
:deep(.ant-card-body) {
  padding: 10px;
}
</style>>